#include <QtTest>

#include "../tests_common.h"

#include <QStringList>

#include "common.h"
#include "bit_range.h"
#include "row_text.h"
#include "rows.h"


using namespace BitWin;


class TestHeaderRow: public QObject
{
    Q_OBJECT

private slots:

    void test_data();
    void test();
};


void TestHeaderRow::test_data()
{
    QTest::addColumn<QString>("title");
    QTest::addColumn<BitRange>("range");
    QTest::addColumn<PRowText>("outdata_expected");
    
    QTest::newRow("Get items[0..4)")
        << QString("Header #0")
        << BitRange(0, 4)
        << LIST_TEXT("0" << "1" << "2" << "3")
    ;
    QTest::newRow("Get items[1, 3)")
        << QString("Header #1")
        << BitRange(1, 3)
        << LIST_TEXT("1" << "2")
    ;
    QTest::newRow("Get items in null range")
        << QString("Header #3")
        << BitRange()
        << EMPTY_LIST_TEXT
    ;
}

void TestHeaderRow::test()
{
    QFETCH(QString, title);
    
    HeaderRow row(title);
    QCOMPARE(row.title(), title);
    
    QFETCH(BitRange, range);
    QFETCH(PRowText, outdata_expected);
    
    QVERIFY(
        !row
            .data(BitWin::BitwiseDataRole + 1, range, STRING_TEXT("1234"))
            .isValid()
    );
    QVERIFY(
        !row
            .data(Qt::DisplayRole, range, STRING_TEXT("1234"))
            .isValid()
    );
    
    QVariant data(
        row.data(BitWin::BitwiseDataRole, range, STRING_TEXT("1234"))
    );
    QVERIFY(data.isValid());
    QVERIFY(data.canConvert<PRowText>());
    PRowText outdata(data.value<PRowText>());
    QCOMPARE(outdata, outdata_expected);
}


QTEST_MAIN(TestHeaderRow)


#include "main.moc"
